package com.game.gui {
	import com.game.data.Data;
	import com.game.events.GameEvent;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.utils.getDefinitionByName;

	public class HomePage extends Sprite{
		
		public function HomePage() {
			
			this.addEventListener(Event.ADDED_TO_STAGE,onInit);
		}
		public function onInit(e:Event=null):void{
			this.removeEventListener(Event.ADDED_TO_STAGE,onInit);
			var HomeScreen:Class = getDefinitionByName("HomeScreen") as Class;
			var screen:MovieClip=new HomeScreen() as MovieClip;
			screen.startButton.buttonMode=true;
			screen.startButton.addEventListener(MouseEvent.CLICK,onStart);
			this.addChild(screen);
		}
		private function onStart(e:Event):void{
			e.target.removeEventListener(MouseEvent.CLICK,onStart);
			while(this.numChildren){
				this.removeChildAt(0);
			}
			
			this.dispatchEvent(new GameEvent(GameEvent.START_GAME));
		}
		public function onEnd(e:Event=null):void{
			var EndScreen:Class = getDefinitionByName("EndScreen") as Class;
			var screen:MovieClip=new EndScreen() as MovieClip;
			screen.gameOverButton.buttonMode=true;
			screen.gameOverButton.addEventListener(MouseEvent.CLICK,onGameOver);
			this.addChild(screen);
		}
		private function onGameOver(e:Event):void{
			e.target.removeEventListener(MouseEvent.CLICK,onGameOver);
			while(this.numChildren){
				this.removeChildAt(0);
			}
			this.dispatchEvent(new GameEvent(GameEvent.GAME_OVER));
		}
	}
}